package com.ruyuan.gateway.sdk.model;

import org.apache.shiro.authc.UsernamePasswordToken;

import java.util.function.Function;

/**
 * @author xx
 */
public class AccountInfoToken extends UsernamePasswordToken {

    private Function<String, UserAccountInfo> userAccountInfoFunction;

    public AccountInfoToken(final String username, final String password, Function<String, UserAccountInfo> function) {
        super(username, password != null ? password.toCharArray() : null, false, null);
        this.userAccountInfoFunction = function;
    }

    @Override
    public Object getPrincipal() {
        return userAccountInfoFunction.apply(getUsername());
    }
}
